#include <algorithm>
#include <iostream>
#include <vector>

/**
 * PAT A 1067 Sort with Swap(0, i)
 */

static int indices[100000];

int main() {
    // Read permutation
    int num;
    scanf("%d", &num);
    for (int i = 0; i < num; i++) {
        int val;
        scanf("%d", &val);
        indices[val] = i;
    }

    // Swap 0 with elements
    int count = 0;
    int lastUnsorted = 1;
    while (true) {
        // Swap 0 with its index
        while (indices[0] != 0) {
            std::swap(indices[0], indices[indices[0]]);
            count++;
        }

        // Search for unsorted numbers
        int unsorted = -1;
        for (int i = lastUnsorted; i < num; i++) {
            if (i != indices[i]) {
                unsorted = i;
                lastUnsorted = unsorted;
                break;
            }
        }
        if (unsorted == -1) break;
        std::swap(indices[0], indices[unsorted]);
        count++;
    }

    printf("%d\n", count);

    return 0;
}
